

//
//  SendDeviceIDTableViewController.m
//  TRSAnalytics
//
//  Created by 824810056 on 2018/2/22.
//  Copyright © 2018年 Miridescent. All rights reserved.
//

#import "SendDeviceIDTableViewController.h"
#import "TRSManager.h"
#import "TRSSystemInfo.h"
#import "TRSHTTPManager.h"
#define kTRSManager  [TRSManager sharedManager]
@interface SendDeviceIDTableViewController ()
@property (nonatomic, strong) NSArray  *cellArray;
@end

@implementation SendDeviceIDTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.cellArray = @[@"情况1（收集网脉设备码、APP自身设备码的对应关系）",@"情况2（非通用需求，用于收集浙江新闻APP新旧设备标识对应关系）",@"情况3（收集网脉设备码、个像设备码的对应关系）"];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.cellArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *mainCellIdentifier = @"mainCellIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:mainCellIdentifier];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:mainCellIdentifier];
    }
    cell.textLabel.text = self.cellArray[indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 2) {
        
        // 发送设备ID的时候要将/ta去掉
        
        NSString *staticURL = [NSString stringWithFormat:@"%@", [kTRSManager.defaultCacheManage deviceInfoWithKey:@"staticURL"]];
        NSArray *staticURLArr = [staticURL componentsSeparatedByString:@"/"];
        NSString *hostUrlStr = [NSString stringWithFormat:@"%@//%@/%@/openapi/appDeviceId?",staticURLArr[0],staticURLArr[2],staticURLArr[3]];
        NSString *param;
        NSString *url;
        
        param = [NSString stringWithFormat:@"wmDeviceId=%@&mpId=%@&deviceId=%@&osVersion=%@&sdkVersion=%@&machineCode=%@&deviceIdJSON={gxDeviceId:'%@'}",
                 [kTRSManager.defaultCacheManage deviceInfoWithKey:@"UUID"],
                 [kTRSManager.defaultCacheManage deviceInfoWithKey:@"mpId"],
                 [kTRSManager.defaultCacheManage deviceInfoWithKey:@"NewDeviceID"],
                 [kTRSManager.defaultCacheManage deviceInfoWithKey:@"ov"],
                 [kTRSManager.defaultCacheManage deviceInfoWithKey:@"sv"],
                 [TRSSystemInfo IDFA],
                 [kTRSManager.defaultCacheManage deviceInfoWithKey:@"gxDeviceID"]];
        
        url = [NSString stringWithFormat:@"%@?%@", hostUrlStr, param];
        
        NSLog(@"sendDeviceIDUrl == %@", url);
        
        [kTRSManager.HTTPManager managerSendDeviceIDWithUrl:url success:^(id response) {
            
        } failure:^(NSError *error) {
            
        }];
    }
}



@end
